<%@page pageEncoding="utf-8" contentType="text/html; charset=utf-8" %>
<%@ include file="/admin/include/init_admin.jsp" %>
<%@ page import="com.welfare.admin.system.*" %>
<%
	 
	String s_code_gubn 		= StringUtil.nvl(request.getParameter("s_code_gubn"));
	String s_codename		= StringUtil.toHan(request.getParameter("s_codename"));

	HashList codeUseYn		= CommonUtil.getCodeList("use_yn");
	
	
	HashMap infos = new HashMap();
	infos.put("code_gubn", "000");
	infos.put("code_name", s_codename);
	 
	SystemDAO dao 			= new SystemDAO();
	HashList codeGroupList	= dao.selectCodeList(infos);
	
	

	infos.put("code_gubn", s_code_gubn);
	infos.put("code_name", "");
	HashList codeList		= dao.selectCodeList(infos);
	
	CommonUtil.reloadCode();
	
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<title><%= SYSTEM_NAME %></title>
	<%@ include file="/admin/include/cssnjs.jsp"  %>
	<script type="text/javascript">
	$(document).ready(function() {
 
		$('#list').find('tr').hover(
				function () { $(this).addClass("hover"); }
			  , function () { $(this).removeClass("hover"); }
			)
			.click(function(){
				$('#searchForm input:hidden[name=s_code_gubn]').val($(this).find('input:hidden[name=code]').val());
				$('#searchForm').attr('action', './codeList.jsp');
				$('#searchForm').submit();
			});

		$("#chk_all").click(function(){
			cfCheckAll();
		});
		
		$('#codeList').find('input[type="text"], select').change(function() {
			$(this).closest('tr').find('input[name="list.job_type"]').val('U');
		});
	});


	function fnSearch() {
		$("#searchForm").attr('action', './codeList.jsp');
		$("#searchForm").submit();
	}

	function fnSave() {
		$("#saveForm").attr('action', './codeListSave.do');
		$("#saveForm").submit();
	}


	function fnAddRow() {
		if ("<%= s_code_gubn %>" == "") {
			alert("코드구분을 선택하세요.")
		} else {
			var txt = '<tr><td align="center"><input type="hidden" name="list.job_type" value="C"/>'
					+ '<input type="hidden" name="list.srch_yn" value=""/>'
					+ '<input type="hidden" name="list.code_gubn" value="<%= s_code_gubn %>"/><input type="checkbox" name="chk" /></td>'
					+ '<td><input type="text" name="list.code" value="" class="wmax"/></td>'
					+ '<td><input type="text" name="list.code_name" value="" class="wmax"/></td>'
					+ '<td><input type="text" name="list.code_desc" value="" class="wmax"/></td>'
					+ '<td><input type="text" name="list.code_num1" value="" class="wmax"/></td>'
					+ '<td><input type="text" name="list.code_num2" value="" class="wmax"/></td>'
					+ '<td><input type="text" name="list.sort" value="" class="wmax"/></td>'
					+ '<td class="c">O</td></tr>';

			$("#codeList").append(txt);
		}
	}

	function fnDeleteRow() {
		var chks = $('input:checkbox[name="chk"]:checked');
		for (var i = 0; i < chks.length; i++) {
			$(chks[i]).closest("tr").hide().find('input[name="list.job_type"]').val('D');
			//$(oThis).closest('div').hide().find('input[name="list.job_type"]').val('D');
		}
	}
	</script>
</head>
<body>
<div id="wrap">
	<div id="page">
		<div id="contents">
			<div class="menu_title">
				<h1>코드관리</h1>
				<p>관리자 > 시스템관리 > <b>코드관리</b></p>
			</div>
			<div class="clear line_01"></div>
			
			

			<form id="searchForm" method="post" action="./codeList.jsp">
			<input type="hidden" name="s_code_gubn" value="<%= s_code_gubn %>"/>
			<table cellpadding="0" cellspacing="0" class="table_01 mt15">
			<colgroup>
				<col width="100px" />
				<col />
			</colgroup>
			<tr>
			    <th><p>코드그룹명</p></th>
				<td class="brx"><input type="text" name="s_codename" value="<%= s_codename %>"/></td>
			</tr>
			</table>

			<div class="mt10 mb10 r">
				<input type="image" class="button" src="../images/btn_search.gif" />
			</div>
			</form>
			
			<!-- <div class="info mt10">
				<p><strong>001~499</strong> : 공통코드(001부터 순차적으로 등록) </p>
				<p><strong>500~599</strong> : 서비스 검색항목 관련 코드 (코드와 코드명을 동일하게 코드명으로 입력)</p>
			</div> -->

			<form id="saveForm" method="post" action="./codeListSave.do">
			<input type="hidden" name="s_code_gubn" value="<%= s_code_gubn %>"/>
			<input type="hidden" name="s_codename" value="<%= s_codename %>"/>
			<div class="fl mt5 mr15">
				<table id="codeGroup" cellpadding="0" cellspacing="0" class="table">
				<colgroup>
					<col width="40"/>
					<col width="160"/>
				</colgroup>
				<thead>
					<tr>
						<th><p>코드</p></th>
						<th><p>코드그룹명</p></th>
					</tr>
				</thead>
				<tbody id="list">
				<%	
					String codeDesc = "기타1";
					String codeInfo = "기타2";
					String selected = "";
				
					for (int i = 0; i < codeGroupList.size(); i++) { 
					
						if (s_code_gubn.equals(codeGroupList.get("code",i))) {
							codeDesc = StringUtil.nvl(codeGroupList.get("code_desc",i),"기타1");
							codeInfo = StringUtil.nvl(codeGroupList.get("code_info",i),"기타2");
							selected = "class=\"selected\"";
						} else {
							selected = "";
						}
				%>
					<tr>
						<td <%=selected%> align="center">
							<input type="hidden" name="code" value="<%= codeGroupList.get("code",i) %>"/>
							<%= codeGroupList.get("code",i) %>
						</td>
						<td <%=selected%>><%= codeGroupList.get("code_name",i) %></td>
					</tr>
				<%	} %>
				</tbody>
				</table>
			</div>
			<div class="fl mt5" >
				<table cellpadding="0" cellspacing="0" class="table" >
				<colgroup>
					<col width="30px"/>
					<col width="80px"/>
					<col width="200px"/>
					<col width="180px"/>
					<col width="60px"/>
					<col width="60px"/>
					<col width="60px"/>
					<col />
				</colgroup>
				<thead>
					<tr>
						<th><p><input type="checkbox" name="chk_all" id="chk_all" class="chk_all"/></p></th>
						<th><p>코드</p></th>
						<th><p>코드명</p></th>
						<th><p><%=codeDesc %></p></th>
						<th><p>Num1</p></th>
						<th><p>Num2</p></th>
						<th><p>정렬순서</p></th>
						<th><p>사용여부</p></th>
					</tr>
				</thead>
				<tbody id="codeList">
			<%	for (int i = 0; i < codeList.size(); i++) { %>
					<tr>
						<td class="c">
							<input type="checkbox" name="chk" />
							<input type="hidden" name="list.job_type" value="X"/>
							<input type="hidden" name="list.code_gubn" value="<%= codeList.get("code_gubn",i) %>"/>
							<input type="hidden" name="list.code" value="<%= codeList.get("code",i) %>"/>
							<input type="hidden" name="list.srch_yn" value="<%= codeList.get("srch_yn",i) %>"/>
						</td>
						<td class="c">
							<%= codeList.get("code",i) %>
						</td>
						<td><input type="text" name="list.code_name" value="<%= codeList.get("code_name",i) %>" class="wmax"/></td>
						<td><input type="text" name="list.code_desc" value="<%= codeList.get("code_desc",i) %>" class="wmax"/></td>
						<td><input type="text" name="list.code_num1" value="<%= codeList.get("code_num1",i) %>" class="wmax"/></td>
						<td><input type="text" name="list.code_num2" value="<%= codeList.get("code_num2",i) %>" class="wmax"/></td>
						<td><input type="text" name="list.sort" value="<%= codeList.get("sort",i) %>" class="wmax"/></td>
						<td>
							<select name="list.use_yn">
							<%= StringUtil.makeOption(codeUseYn, codeList.get("use_yn", i)) %>
							</select>
						</td>
					</tr>
			<%	} %>
				</tbody>
				</table>

				<div class="clear"></div>
				<div class="mt20 mb10 c">
					<img src="../images/btn_addrow.gif" class="pointer" onclick="fnAddRow()"/>
					<img src="../images/btn_delrow.gif" class="pointer" onclick="fnDeleteRow()"/>
					<input type="image" class="button" src="../images/btn_save.gif" />
				</div>
			</div>


			</form>
		</div>
	</div>
</div>
</body>
</html>
